# summary of categorical variables
tabulate gender category, column exact
tabulate ards_severity category, column exact
tabulate micu_flg category, column exact
tabulate sepsis_flg category, column exact
tabulate icd9_group category, column exact

tabulate icu_exp_flg category, column exact
tabulate mort_28_day category, column exact
tabulate mort_1_year category, column exact
tabulate mort_2_year category, column exact

#post-hoc analysis
oneway gender_num category, sidak
oneway ards_severity category, sidak
oneway micu_flg category, sidak
oneway sepsis_flg category, sidak
oneway icd9_group category, sidak
oneway icu_exp_flg category, sidak
oneway mort_28_day category, sidak
oneway mort_1_year category, sidak
oneway mort_2_year category, sidak

oneway age category, sidak
oneway height category, sidak
oneway weight_first category, sidak
oneway sapsi_first category, sidak
oneway sofa_first category, sidak
oneway elix_mimic_28_day category, sidak
oneway icustay_los category if icu_exp_flg==0, sidak
oneway vent_time_day category, sidak
oneway survival_day category, sidak



#pair-wise exact test
tabulate gender category if category!="ADMIN", column exact
tabulate gender category if category!="LATE", column exact
tabulate gender category if category!="CONTROL", column exact

tabulate micu_flg category if category!="ADMIN", column exact
tabulate micu_flg category if category!="LATE", column exact
tabulate micu_flg category if category!="CONTROL", column exact

tabulate sepsis_flg category if category!="ADMIN", column exact
tabulate sepsis_flg category if category!="LATE", column exact
tabulate sepsis_flg category if category!="CONTROL", column exact

tabulate icd9_group category if category!="ADMIN", column chi
tabulate icd9_group category if category!="LATE", column chi
tabulate icd9_group category if category!="CONTROL", column chi

tabulate ards_severity category if category!="ADMIN", column exact
tabulate ards_severity category if category!="LATE", column exact
tabulate ards_severity category if category!="CONTROL", column exact


tabulate icu_exp_flg category if category!="ADMIN", column exact
tabulate icu_exp_flg category if category!="LATE", column exact
tabulate icu_exp_flg category if category!="CONTROL", column exact

tabulate mort_28_day category if category!="ADMIN", column exact
tabulate mort_28_day category if category!="LATE", column exact
tabulate mort_28_day category if category!="CONTROL", column exact

tabulate mort_1_year category if category!="ADMIN", column exact
tabulate mort_1_year category if category!="LATE", column exact
tabulate mort_1_year category if category!="CONTROL", column exact

tabulate mort_2_year category if category!="ADMIN", column exact
tabulate mort_2_year category if category!="LATE", column exact
tabulate mort_2_year category if category!="CONTROL", column exact



#summary of continuous vairables
summarize age if category=="ADMIN", detail
summarize age if category=="LATE", detail
summarize age if category=="CONTROL", detail

summarize height if category=="ADMIN", detail
summarize height if category=="LATE", detail
summarize height if category=="CONTROL", detail

summarize weight_first if category=="ADMIN", detail
summarize weight_first if category=="LATE", detail
summarize weight_first if category=="CONTROL", detail

summarize sapsi_first if category=="ADMIN", detail
summarize sapsi_first if category=="LATE", detail
summarize sapsi_first if category=="CONTROL", detail

summarize sofa_first if category=="ADMIN", detail
summarize sofa_first if category=="LATE", detail
summarize sofa_first if category=="CONTROL", detail

summarize elix_28_day if category=="ADMIN", detail
summarize elix_28_day if category=="LATE", detail
summarize elix_28_day if category=="CONTROL", detail

summarize elix_mimic_28_day if category=="ADMIN", detail
summarize elix_mimic_28_day if category=="LATE", detail
summarize elix_mimic_28_day if category=="CONTROL", detail

summarize icustay_los if category=="ADMIN" & icu_exp_flg==0, detail
summarize icustay_los if category=="LATE" & icu_exp_flg==0, detail
summarize icustay_los if category=="CONTROL" & icu_exp_flg==0, detail

summarize vent_time_day if category=="ADMIN", detail
summarize vent_time_day if category=="LATE", detail
summarize vent_time_day if category=="CONTROL", detail

summarize day_to_onset if category=="ADMIN", detail
summarize day_to_onset if category=="LATE", detail
summarize day_to_onset if category=="CONTROL", detail

summarize survival_day if category=="ADMIN" & sensor_flg==0, detail
summarize survival_day if category=="LATE" & sensor_flg==0, detail
summarize survival_day if category=="CONTROL" & sensor_flg==0, detail

#vent_free for 28 days
generate surv_temp= survival_day
replace surv_temp =28 if survival_day>28
generate vent_free=surv_temp-vent_time_day 
replace vent_free=0 if vent_free<0

summarize vent_free if category=="ADMIN", detail
summarize vent_free if category=="LATE", detail
summarize vent_free if category=="CONTROL", detail

#ranksum tests
ranksum age if category!="ADMIN", by (category)
ranksum age if category!="LATE", by (category)
ranksum age if category!="CONTROL", by (category)

ranksum height if category!="ADMIN", by (category)
ranksum height if category!="LATE", by (category)
ranksum height if category!="CONTROL", by (category)

ranksum weight_first if category!="ADMIN", by (category)
ranksum weight_first if category!="LATE", by (category)
ranksum weight_first if category!="CONTROL", by (category)

ranksum sapsi_first if category!="ADMIN", by (category)
ranksum sapsi_first if category!="LATE", by (category)
ranksum sapsi_first if category!="CONTROL", by (category)

ranksum sofa_first if category!="ADMIN", by (category)
ranksum sofa_first if category!="LATE", by (category)
ranksum sofa_first if category!="CONTROL", by (category)

ranksum elix_28_day if category!="ADMIN", by (category)
ranksum elix_28_day if category!="LATE", by (category)
ranksum elix_28_day if category!="CONTROL", by (category)

ranksum icustay_los if category!="ADMIN", by (category)
ranksum icustay_los if category!="LATE", by (category)
ranksum icustay_los if category!="CONTROL", by (category)

ranksum vent_time_day if category!="ADMIN", by (category)
ranksum vent_time_day if category!="LATE", by (category)
ranksum vent_time_day if category!="CONTROL", by (category)

ranksum day_to_onset if category!="CONTROL", by (category)

ranksum survival_day if category!="ADMIN", by (category)
ranksum survival_day if category!="LATE", by (category)
ranksum survival_day if category!="CONTROL", by (category)

kwallis survival_day, by (category) 
kwallis elix_mimic_28_day, by (category)
